package com.zyz.forum.controller;

import com.zyz.forum.common.AppResult;
import com.zyz.forum.common.ResultCode;
import com.zyz.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

@Api(tags = "测试类的相关接口")
@RestController
@RequestMapping("/test")
public class TestController {

    @ApiOperation("测试接口1，显示你好Spring boot")
    @PostMapping("/hello")
    public String hello() {
        return "hello spring boot....";
    }

    @ApiOperation("测试接口2，显示抛出的异常信息")
    @GetMapping("/exception")
    public AppResult testException() {
        throw new RuntimeException();
    }

    @ApiOperation("测试接口3，显示抛出的自定义异常")
    @GetMapping("/appException")
    public AppResult testAppException() throws ApplicationException {
        throw new ApplicationException(AppResult.failed(ResultCode.FAILED_LOGIN));
    }

    @ApiOperation("测试接口4，显示传入的名字信息")
    @PostMapping("/helloByName")
    public String helloByName(@ApiParam("传入姓名") @RequestParam("name") String name) {
        return "hello " + name;
    }
}
